package com.springboot.code.String;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * DESC:
 *
 * @author WangJie
 * @date Created in 2023-02-26 9:19
 */
public class FileUtils {
    //G:\DataBase
    public static void main(String[] args) {
        // System.out.println(deleteFile("G:\\DataBase\\deleteFile.txt"));
        // System.out.println(getPastDate(7,new Date()));
    }

    private static boolean deleteFile(String sPath) {
        boolean flag = false;
        File file = new File(sPath);
        // 路径为文件且不为空则进行删除
        if (file.isFile() && file.exists()) {
            file.delete();
            flag = true;
        }
        return flag;
    }

    public static String getPastDate(int past,Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - past);
        Date today = calendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String result = sdf.format(today);
        return result;
    }
}
